import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutterapp/LoginWidget.dart';
import 'package:flutterapp/util/SpUtil.dart';

class MyPageWidget extends StatefulWidget {
  final String title;
  MyPageWidget({Key key, this.title}) : super(key: key);

  @override
  MyPageWidgetState createState() => MyPageWidgetState();
}

class MyPageWidgetState extends State<MyPageWidget> {

  bool isLogin ;

  @override
  void initState() {
    isLogin = SpUtil.sharedPreferences.getBool('isLogin')??false;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        decoration: BoxDecoration(
            gradient: LinearGradient(
                begin: Alignment.topLeft,
                end: Alignment.bottomRight,
                colors: [
              Color(0xFFFB6659),
              Color(0xFFFED102),
              Color(0xFFFED102),
            ])),
        child: Container(
          margin: EdgeInsets.only(top: 30),
          child: Column(
            children: <Widget>[
              InkWell(
                onTap: (){
                  if(isLogin){
                    showDialog(
                        context: context,
                        child: AlertDialog(
                          shape:RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
                          title: Text('提示'),
                          content: SingleChildScrollView(
                            child: ListBody(
                              children: <Widget>[
                                Text('退出登录？'),
                              ],
                            ),
                          ),
                          actions: <Widget>[
                            FlatButton(
                              child: Text('确定',style: TextStyle(color: Color(0xFFF16050)),),
                              onPressed: () {
                                SpUtil.sharedPreferences.setBool('isLogin', false);
                                setState(() {
                                  isLogin = false;
                                });
                                Navigator.pop(context);
                              },
                            ),
                            FlatButton(
                              child: Text('取消',style: TextStyle(color: Color(0xFFF16050)),),
                              onPressed: () {
                                Navigator.pop(context);
                              },
                            ),
                          ],
                        )
                    );
                  }else{
                    Navigator.push(context, MaterialPageRoute(
                        builder: (context){
                          return LoginWidget();
                        }
                    ));
                  }
                },
                child: Container(
                  margin: EdgeInsets.only(bottom: 25),
                  child: Row(
                    children: <Widget>[
                      Container(
                        width: 50,
                        height: 50,
                        margin: EdgeInsets.only(top: 30, left: 20),
                        child: ClipOval(
                          child: Image.asset(isLogin?'assets/images/avatar.png':'assets/images/defaultAvatar.png'),
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: 25, left: 20),
                        child: Text(
                          isLogin?'admin':'点击头像登录',
                          style: TextStyle(color: Colors.white),
                        ),
                      ),
                      Spacer(),
                      Container(
                        margin: EdgeInsets.only(top: 25, right: 20),
                        child: Icon(
                          Icons.keyboard_arrow_right,
                          size: 20,
                          color: Colors.white,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              Expanded(
                child: Container(
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.only(
                        topLeft: Radius.circular(20),
                        topRight: Radius.circular(20)),
                    color: Color(0xFFFAFAFA),
                  ),
                  child: Column(
                    children: <Widget>[
                      ListTile(
                        trailing: Icon(Icons.keyboard_arrow_right,color: Colors.grey,),
                        leading: Image.asset('assets/images/vip.png',width: 20,height: 20,),
                        title: Text('会员服务'),
                      ),
                      Divider(
                        height: 1,
                        indent: 15,
                        endIndent: 15,
                        color: Color(0xFFDDDDDD),
                      ),
                      ListTile(
                        trailing: Icon(Icons.keyboard_arrow_right,color: Colors.grey,),
                        leading: Image.asset('assets/images/circle.png',width: 23,height: 23,),
                        title: Text('树友圈'),
                      ),
                      Divider(
                        height: 1,
                        indent: 15,
                        endIndent: 15,
                        color: Color(0xFFDDDDDD),
                      ),
                      ListTile(
                        trailing: Icon(Icons.keyboard_arrow_right,color: Colors.grey,),
                        leading: Image.asset('assets/images/help.png',width: 19,height: 19,),
                        title: Text('使用帮助'),
                      ),
                      Divider(
                        height: 1,
                        indent: 15,
                        endIndent: 15,
                        color: Color(0xFFDDDDDD),
                      ),
                      ListTile(
                        trailing: Icon(Icons.keyboard_arrow_right,color: Colors.grey,),
                          leading: Image.asset('assets/images/setting.png',width: 19,height: 19,),
                        title: Text('系统设置'),
                      ),
                      Divider(
                        height: 1,
                        indent: 15,
                        endIndent: 15,
                        color: Color(0xFFDDDDDD),
                      ),
                      ListTile(
                        trailing: Icon(Icons.keyboard_arrow_right,color: Colors.grey,),
                        leading: Image.asset('assets/images/update.png',width: 22,height: 22,),
                        title: Text('检查更新'),
                      ),
                      Divider(
                        height: 1,
                        indent: 15,
                        endIndent: 15,
                        color: Color(0xFFDDDDDD),
                      ),
                      ListTile(
                        trailing: Icon(Icons.keyboard_arrow_right,color: Colors.grey,),
                        leading: Image.asset('assets/images/about.png',width: 20,height: 20,),
                        title: Text('关于我们'),
                      ),
                      Divider(
                        height: 1,
                        indent: 15,
                        endIndent: 15,
                        color: Color(0xFFDDDDDD),
                      ),
                    ],
                  ),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
